const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
　　
const path = require('path')

// var os = require('os');
// var IPv4,hostName;
// hostName=os.hostname();
// for(var i=0;i<os.networkInterfaces().en0.length;i++){
//     if(os.networkInterfaces().en0[i].family=='IPv4'){
//         IPv4=os.networkInterfaces().en0[i].address;
//     }
// }
// console.log('----------local IP: '+IPv4);
// console.log('----------local host: '+hostName);


module.exports = {
  mode: 'none',
  entry: './src/main.js',
  output: {
    filename: '[name]-[contenthash:8].bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  optimization: {
    // splitChunks: {
    //   // 提取所有公共模块到单独的文件中
    //   chunks: 'all'
    // }
  },
  module: {
    rules: [
      // {
      //   test: /\.js$/,
      //   use: 'babel-loader'
      // },
      {
        test: /\.js$/, 
        exclude: /node_modules/, 
        use: 'eslint-loader',
        enforce: "pre"
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1
            }
          },
          'postcss-loader'
        ]
      },
      {
        test: /\.less$/,
        use: [
          'style-loader',
          'css-loader',
          'postcss-loader',
          'less-loader'
        ]
      },
      // {
      //   test: /\.html$/,
      //   use: 'html-loader'
      // },
      {
        test: /\.vue$/,
        use: 'vue-loader'
      },
      {
        test: /\.(png|jpe?g|gif)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10 * 1024,
            outputPath: 'img',
            name: '[name].[ext]',
            esModule: false // vue使用的是commonjs语法规范，而file-loader/url-loader使用的es module语法规范，处理图片时不用es module的语法
          }
        }
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html'
    }),
    new webpack.DefinePlugin({
      BASE_URL: JSON.stringify("./")
    })
  ]
}